
from django.http import HttpResponse, FileResponse
# 编码解码
import json

class Result:
    def __init__(self, code, msg, data):
        self.code = code
        self.msg = msg
        self.data = data
    def serialize(self):
        return {'code': self.code, 'msg': self.msg, 'data': self.data}
        # actually python object

    def http_response(self):
        return HttpResponse(json.dumps(self.serialize()),
                            # content_type='application/json',
                            headers={'Access-Control-Allow-Origin': '*'})